/**
 * 个人设置组件
 * 根据personal.settings.jumpToPage开关决定跳外链还是弹弹窗
 */

import React, { useState } from 'react';
import { getFeature } from 'utils/features';
import PersonalSettingsDialog from './components/dialog';
import customNavs from './customNavs';

const Personalsettings = ({ type, defaultVisible = false, onClose, ...others }) => {
  const [visible, setVisible] = useState(defaultVisible);

  if (getFeature('personal.settings.jumpToPage')) {
    return (
      <a
        href={`${getFeature('personal.settings.jumpToPage.urlPrefix')}${type}`}
        target="_blank"
        {...others}
      />
    );
  }

  return (
    <>
      {others.children ? (
        <a
          {...others}
          onClick={() => {
            setVisible(true);
          }}
        />
      ) : null}
      <PersonalSettingsDialog
        selectedNavKey={type}
        customNavs={customNavs}
        visible={visible}
        onClose={() => {
          setVisible(false);
          onClose && onClose();
        }}
      />
    </>
  );
};

export default Personalsettings;
